<template>
	<view class="bi-project-select" @click="handleClick">
		<view class="bi-project-select__value" v-if="innerValue">
			{{ innerValue? '点击修改处理人': '点击选择处理人' }}
		</view>
		<view v-else class="bi-project-select__placeholder">点击选择处理人</view>
	</view>
</template>
<script>
	import { buildUrl } from '@/utils/url'
	import { unique } from '@/utils/string'
	import Event from '@/utils/event.js'
	export default {
		name: 'BiProjectSelect',
		props: {
			value: {
				type: String
			},
			text: {
				type: String
			},
			confirmBack: {
				type: Boolean,
				default: true
			}
		},
		data () {
			return {
				innerName: this.text || ''
			}
		},
		computed: {
			innerValue: {
				get () {
					return this.value
				},
				set (val) {
					this.$emit('input', val)
				}
			}
		},
		watch: {
			text () {
				this.innerName = this.text || ''
			}
		},
		created () {
			this.id = unique('project_select_')
      console.log('this.text============', this.id)
			Event.on(this.id, ({ selection }) => {
				if (selection && selection.length) {
          let ids = selection.map(item=>item.userId)
          let names = selection.map(item=>item.nickName)
          this.innerValue = ids
          this.innerName = names
        } else {
					this.innerValue = ''
					this.innerName = ''
				}
        uni.navigateBack()
        this.$emit('change', {
					item: selection
				})
			})
		},
		methods: {
			handleClick () {
				const params = {
					eventName: this.id,
					multiple: true
				}
				if (this.innerValue) {
					params.value = this.innerValue
				}
				uni.navigateTo({
					url: buildUrl('/packages/project/project-select/project-select', params)
				})
			}
		}
	}
</script>

<style>
	.bi-project-select__value{
		min-height: 24px;
		line-height: 24px;
		padding: 8px 0;
		text-align: right;
    color: #409049;
    font-weight: bold;

  }
	.bi-project-select__placeholder{
		height: 24px;
		line-height: 24px;
		padding: 8px 0;
		text-align: right;
    font-weight: bold;
    color: #409049;
  }
</style>